<%@ page contentType="text/html;charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>验证</title>
<meta http-equiv="Cache-Control" content="no-store"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
<meta name="keywords" content="" />
<meta name="description" content="" />
<style>
	body{
		font: 12px/1.4 Arial, sans-serif;
	}
	table td{
		border: 1px solid #ACA899;
		margin: 0px;
		padding: 2px;
		text-align: left;
		background-color: white;
		line-height: 23px;
	}
	
	table tbody tr:nth-child(odd) td{
		
	}
	
	table>thead>tr>td{
		text-align: left;
		line-height: 35px;
		background-color: #E3D5D5;
		color: black;
	}
	
	table tbody tr:last-child td{
		border-bottom: 1px solid black;
	}
	
	li{
		cursor: pointer;
	}
	li:HOVER{
		text-decoration: underline;
	}

	.container{
		margin: 0 auto;
		min-height: 500px;
		width: 90%;
	}
	.left{
		width: 19%;
		float: left;
		min-height: 600px;
		max-height: 685px;
		height: 685px;
		overflow: auto;
		margin-top: 30px; 
	}
	.right{
		width: 80%;
		float: right;
		min-height: 600px;
		margin-top: 30px; 
	}
	.display{
		max-height: 500px;
		overflow: auto;
	}
	.sminput{
		height: 130px;
		min-height: 120px;
	}
	.content{
	}
	
	.selected{
		background-color: #5BB75B;
	}
	
	
</style>

<script language="javascript">
	$(function(){
		$("tr").click(function(){
			if($(this).children().hasClass("selected")){
				$("td").removeClass("selected");
			}else{
				$("td").removeClass("selected");
				$(this).children().addClass("selected");
			}
		})
		
		$("li").click(function(){
			var val =$(this).text();
			$("#sqlContent").text("select * from " + val);
			$("#do_sub").click();
		})
		
		$("#getAll").click(function(){
			$("#all").val("yes");
			$("#do_sub").click();
			return false;
		});
		
		
		$("#do_clear").click(function(){
			$("#sqlContent").text("");
		})
		
		$("#where").click(function(){
			var content = $("#sqlContent").text();
			$("#sqlContent").text(content + " where ");
			$("#sqlContent").focus();
		})
	})

</script>
</head>
<body>

	<div class="container">
		<div class="left">
			<ul>
				<c:forEach items="${all_tables}" var="one_table">
				<li>${one_table}</li>
				</c:forEach>
			</ul>
		</div>
		<div class="right">
			<div class="sminput">
				<form action="${pageContext.request.contextPath}/dev/sql.do" method="post">
					<div style="clear: both; overflow: hidden;">
						<div style="float: left;">
							<input type="hidden" name="action" value="executeSql" />
							<input id="all" type="hidden" name="all" value="no" />
							<input id="do_sub" type="submit" class="btn" value="执行" />
							<input id="do_clear" type="button" class="btn" value="清除" />
						</div>
						<div style="float: left; margin-left: 50px;">
							<input type="button" id="where" class="btn" value="where" />
						</div>
						<div style="float: right; margin-right: 10px;">
							<select class="selectbox">
									<option>执行后得到的字段</option>
								<c:forEach items="${select_col_name}" var="col">
					         		<option>${col}</option>
					        	 </c:forEach>
							</select>
							
						</div>
					</div>
					<div>
					<textarea id="sqlContent" name="sql" style="margin: 2px; width: 100%; height: 75px; max-height: 75px;min-height: 75px;">${p_sql}</textarea>
					</div>
					<br />
				</form>
			</div>
			<div style="margin-bottom: 10px;">${p_sql}</div>
			<div>
				<c:if test="${select_count_num > 0}" >一共查到的数据是: ${select_count_num} 条</c:if>
			</div>
			<div>${error}</div>
			<hr />
			<div style="margin-bottom: 5px;">
				<c:if test="${select_count_num > 15}" ><button id="getAll" class="btn-long">获得全部数据</button></c:if>
			</div>
			<div class="display">
				<div class="content">
					<table cellspacing="0" cellpadding="0">
						<thead>
							 <tr>
					         	<c:forEach items="${select_col_name}" var="col">
					         		<td nowrap="nowrap">${col}</td>
					        	 </c:forEach>
					         </tr>
						</thead>
						<tbody>
						<c:forEach items="${select_result}" begin="1" var="row">
					         <tr>
					         	<c:forEach items="${row}" var="col">
					         		<td nowrap="nowrap">					         		
					         		${col}
					         		<c:if test="${col == '[CLOB]'}" >
					         			<button>..</button>
					         		</c:if>
					         		</td>
					        	 </c:forEach>
					         </tr>
						</c:forEach>
						</tbody>
					</table>
				</div>
			</div>
		</div>		
	</div>
</body>
</html>